package com.tanhua.dubbo.server.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.common.mapper.UserFreezeMapper;
import com.tanhua.common.pojo.UserFreeze;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserFreezeService {

    @Autowired
    private UserFreezeMapper userFreezeMapper;

    //查询是否冻结
    public UserFreeze findUserFreeze(Integer userId) {
        /*UserFreeze userFreeze1=new UserFreeze();
        userFreeze1.setUserId(5);
        userFreeze1.setFreezingtime(1);
        userFreeze1.setFreezingrange(1);
        userFreeze1.setReasonsforfreezing("恶意攻击");
        userFreeze1.setFrozenremarks("攻击管理员");
        userFreezeMapper.insert(userFreeze1);*/
        LambdaQueryWrapper<UserFreeze> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(UserFreeze::getUserId,userId);
        return userFreezeMapper.selectOne(wrapper);
    }

    //添加冻结
    public Integer saveFreeze(UserFreeze userFreeze) {
        return userFreezeMapper.insert(userFreeze);
    }

    //修改冻结信息
    public Integer updateFreeze(UserFreeze userFreeze) {
        /*Query query=Query.query(Criteria.where("userId").is(userFreeze.getUserId()));
        Update update=new Update();
        update.set("freezingTime",userFreeze.getFreezingTime())
                .set("freezingRange",userFreeze.getFreezingRange())
                .set("reasonsForFreezing",userFreeze.getReasonsForFreezing())
                .set("frozenRemarks",userFreeze.getFrozenRemarks());
        UpdateResult updateResult = mongoTemplate.updateFirst(query, update, UserFreeze.class);*/
        LambdaQueryWrapper<UserFreeze> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(UserFreeze::getUserId,userFreeze.getUserId());
        int i = userFreezeMapper.update(userFreeze,wrapper);
        return i;
    }

    //取消冻结
    public Integer deleteFreeze(Long userId) {
        LambdaQueryWrapper<UserFreeze> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(UserFreeze::getUserId,userId);
        int delete = userFreezeMapper.delete(wrapper);
        return delete;
    }
}
